package com.example.acamp.dip;

import android.app.Activity;
import android.os.Bundle;

import com.example.acamp.dip.dummy.DummyContent;

public class PicListActivity extends Activity
        implements PicListFragment.Callbacks {

    private boolean mTwoPane;
    private boolean mExternalSaveLocation;

    public boolean isExternalSaveLocation() {
    	return mExternalSaveLocation;
    }
    
    public void toggleSaveLocation() {
    	mExternalSaveLocation = !mExternalSaveLocation;
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.one_pane);

        // if the savedInstanceState is not null, we don't initialize
        // the fragment
        if ( null == savedInstanceState ) {
	        // Initialize our dummy data      	
	        DummyContent.Init(this);
	
	        PicListFragment listFragment = new PicListFragment();
	        getFragmentManager().beginTransaction()
	        	.replace(R.id.first_pane, listFragment)
	        	.commit();
        }
        
        if (findViewById(R.id.second_pane) != null) {
            mTwoPane = true;
        }
    }

    @Override
    public void onItemSelected(String id) {
        if (mTwoPane) {
            Bundle arguments = new Bundle();
            arguments.putString(PicDetailFragment.ARG_ITEM_ID, id);
            PicDetailFragment fragment = new PicDetailFragment();
            fragment.setArguments(arguments);
            getFragmentManager().beginTransaction()
                    .replace(R.id.second_pane, fragment)
                    .commit();

        } else {
            Bundle arguments = new Bundle();
            arguments.putString(PicDetailFragment.ARG_ITEM_ID, id);
            PicDetailFragment fragment = new PicDetailFragment();
            fragment.setArguments(arguments);
            getFragmentManager().beginTransaction()
                    .replace(R.id.first_pane, fragment)
                    .addToBackStack("Detail")
                    .commit();        	
        }
    }
}
